import { checkStatementOrder } from '@/api/order'
import { ref } from 'vue'
import { OrderAPIRequestParam } from '@/typings/api/order'

const useOrderFinishCheck = () => {
  const orderFinishCheckLoading = ref(false)
  const form = ref<OrderAPIRequestParam.CheckStatementOrder>({
    checkType: 1,
    id: '',
    price: 0,
    remark: '',
    surePrice: 0,
  })
  const unAgree = async (id: string) => {
    orderFinishCheckLoading.value = true
    form.value.checkType = 2
    const res = await checkStatementOrder(id, form.value)
    orderFinishCheckLoading.value = false
    return res.data as { code: number; success: boolean; message: string; data: object }
  }
  const agree = async (id: string) => {
    orderFinishCheckLoading.value = true
    form.value.checkType = 1
    const res = await checkStatementOrder(id, form.value)
    orderFinishCheckLoading.value = false
    return res.data as { code: number; success: boolean; message: string; data: object }
  }

  return {
    form,
    orderFinishCheckLoading,
    agree,
    unAgree,
  }
}

export default useOrderFinishCheck
